package com.mccken.practice.top100.Top_1$20.Top_13;

import java.util.Arrays;

/**
 * @program: mccken-collect
 * @description:
 * @author: mccken
 * @create: 2024-01-02 19:42
 **/
public class Rotate {

	/*
	这个题要用翻转做，
	环形替换，实在比较复杂，直接忽略
	 */
	public void rotate(int[] nums, int k) {
		int n = nums.length;
		k = k % n;
		
		reverse(nums, 0, n-1);
		reverse(nums, 0, k-1);
		reverse(nums, k, n-1);

		System.out.println(Arrays.toString(nums));
	}
	
	public void reverse(int[] nums, int start, int end) {
		while(start < end) {
			int temp = nums[start];
			nums[start] = nums[end];
			nums[end] = temp;
			
			start++;
			end--;
		}
	}

	public static void main(String[] args) {
		Rotate rotate = new Rotate();
		rotate.rotate(new int[]{1,2,3,4,5,6,7}, 3);
	}

}
